#!/bin/bash
##8.Dashboard集群
# http://www.cnblogs.com/elvi/p/7736724.html
#####在controller1安装配置

#安装dashboard
yum install openstack-dashboard -y

#配置
cp /etc/openstack-dashboard/local_settings{,.bak}
#egrep -v '#|^$' /etc/openstack-dashboard/local_settings #显示默认配置
Setfiles=/etc/openstack-dashboard/local_settings
sed -i 's#_member_#user#g' $Setfiles
sed -i 's#OPENSTACK_HOST = "127.0.0.1"#OPENSTACK_HOST = "controller"#' $Setfiles
##允许所有主机访问#
sed -i "/ALLOWED_HOSTS/cALLOWED_HOSTS = ['*', ]" $Setfiles
#去掉memcached注释#
sed -in '153,158s/#//' $Setfiles 
sed -in '160,164s/.*/#&/' $Setfiles
sed -i 's#UTC#Asia/Shanghai#g' $Setfiles
sed -i 's#%s:5000/v2.0#%s:5000/v3#' $Setfiles
sed -i '/ULTIDOMAIN_SUPPORT/cOPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT = True' $Setfiles
sed -i "s@^#OPENSTACK_KEYSTONE_DEFAULT@OPENSTACK_KEYSTONE_DEFAULT@" $Setfiles
echo '
#set
OPENSTACK_API_VERSIONS = {
    "identity": 3,
    "image": 2,
    "volume": 2,
}
#'>>$Setfiles
#
# vim /etc/httpd/conf.d/openstack-dashboard.conf"
# 在WSGISocketPrefix run/wsgi下面加一行代码："
# WSGIApplicationGroup %{GLOBAL}"

sed -i '/WSGISocketPrefix run\/wsgi/a\WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/openstack-dashboard.conf
systemctl restart httpd

#访问
# http://vip/dashboard/

# http集群，前面步骤已配置http://www.cnblogs.com/elvi/p/7736570.html

#########其它节点配置controller2，controller3
#安装dashboard
ssh controller2 "yum install -y openstack-dashboard"
ssh controller3 "yum install -y openstack-dashboard"

#同步controller1配置到其它节点
rsync -avzP  -e 'ssh -p 22'  /etc/openstack-dashboard/local_settings  controller2:/etc/openstack-dashboard/
rsync -avzP  -e 'ssh -p 22'  /etc/openstack-dashboard/local_settings.bak  controller2:/etc/openstack-dashboard/
rsync -avzP  -e 'ssh -p 22'  /etc/openstack-dashboard/local_settings  controller3:/etc/openstack-dashboard/
rsync -avzP  -e 'ssh -p 22'  /etc/openstack-dashboard/local_settings.bak  controller3:/etc/openstack-dashboard/

ssh controller2 "sed -i '/WSGISocketPrefix run\/wsgi/a\WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/openstack-dashboard.conf"
ssh controller3 "sed -i '/WSGISocketPrefix run\/wsgi/a\WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/openstack-dashboard.conf"

#重启http
ssh controller2  "systemctl restart httpd"
ssh controller3  "systemctl restart httpd"